<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Controller\store;

use App\Kernel\Util\StoreJwtInstance;
use App\Service\Store\StoreService;
use App\Request\Store\Auth\registerRequest;
use App\Service\Store\UserService;
use Hyperf\Guzzle\ClientFactory;
use App\Middleware\User\StoreMiddleware;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 后台用户鉴权控制器
 *
 * @AutoController()
 * @Middleware(StoreMiddleware::class)
 * @author 张昊(2396675557@qq.com)
 * @package App\Controller\admin
 */
class UserController extends Controller
{

    /**
     * 后台用户服务
     * @Inject
     * @var StoreService
     */
    private $store_service;

    /**
     * @Inject
     * @var UserService
     */
    public $user_service;

    /**
     * 后台用户资料接口
     */
    public function info()
    {
        $result = $this->store_service->store_dao->first(storeId());

        $result->makeHidden(['id','created_at','status','birthday','email','sign','sex','safe_pwd']);
        $result = $result->toArray();
        // 根据权限添加菜单数据
        $result = $this->store_service->joinStoreMenus($result);

        $this->success($result);
    }

    /**
     * 会员列表
     */
    public function list()
    {
        $params = $this->request->all();

        $result = $this->user_service->list($params);

        $this->success($result);
    }

    /**
     * 会员积分增加
     */
    public function integralAdd()
    {
        $user_id = (int)$this->request->input('user_id', 0);
        $num = (float)$this->request->input('num', 0.00);
        $remark = (string)$this->request->input('remark', "系统赠送");

        $result = $this->user_service->integralAdd([
            'user_id' => $user_id,
            'num' => $num,
            'remark' => $remark,
        ]);

        $this->success($result);
    }

    /**
     * 会员积分减少
     */
    public function integralReduce()
    {
        $user_id = (int)$this->request->input('user_id', 0);
        $num = (float)$this->request->input('num', 0.00);
        $remark = (string)$this->request->input('remark', "系统减少");

        $result = $this->user_service->integralReduce([
            'user_id' => $user_id,
            'num' => $num,
            'remark' => $remark,
        ]);

        $this->success($result);
    }

    /**
     * 会员设置渠道商
     */
    public function serUserChannel()
    {
        $user_id = (int)$this->request->input('user_id', 0);

        $result = $this->user_service->serUserChannel($user_id);

        $this->success($result);
    }

    /**
     * 查询会员下级
     */
    public function lowerLevel()
    {
        $user_id = (int)$this->request->input('user_id', 0);

        $result = $this->user_service->lowerLevel($user_id);

        $this->success($result);
    }
}